package com.ruoyi.monitor.model.Observer;

import com.ruoyi.monitor.domain.Pollutant;
import com.ruoyi.monitor.model.Abstract.Observer;
import com.ruoyi.monitor.model.Abstract.Subject;
import com.ruoyi.monitor.model.Subject.QualitySubject;
import com.ruoyi.monitor.service.ISysMessageService;
import com.ruoyi.monitor.utils.Email.MailCenter;
import com.ruoyi.monitor.utils.Msg.MsgUtil;
import com.ruoyi.monitor.utils.Msg.SMSCenter;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Queue;

@Component
public class QualityObserver implements Observer {
    private Pollutant pollutant ;
    @Autowired
    private SMSCenter center;
    @Autowired
    private MsgUtil msgUtil;

    private String rank = "";

    public Pollutant getPollutant() {
        return pollutant;
    }

    public void setPollutant(Pollutant pollutant) {
        this.pollutant = pollutant;
    }

    @Override
    public void update(Subject subject) {
        List<Pollutant> pollutants = ((QualitySubject) subject).getPollutants();

        System.out.println("观察者更新完毕......");
        try{
           send(pollutants);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public void send(List<Pollutant> pollutants) {
        center.sendAll(pollutants);
    }




}
